
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int data[] = {2,4,1,7,5,3,2,9,6,0,5,1,8,0};

void sort_counter(int d[],int n,int k)
{
	int i, j = 0;
	k++;
	int* counter = (int*)malloc(sizeof(int)*k);
	memset(counter,0,sizeof(int)*k);
	for(i = 0; i < n; ++i)
	{
		++counter[d[i]];
	}
	for(i = 0; i < k; ++i)
	{
		while(counter[i]-- >0)
		{
			d[j++] = i;
		}
	}

	free(counter);
}
int main()
{
	int i,j;
	for(j = 0 ; j < 14; j++)
	{
		if(j == 0)
			printf("排序前：%d ",data[j]);
		else
			printf("%d ",data[j]);
	}
	printf("\n");
	sort_counter(data,14,9);
	for(i = 0; i < 14; i++)
	{
		if(i == 0)
			printf("排序后：%d ",data[i]);
		else
			printf("%d ",data[i]);
	}
	return 0;

}
